﻿using ERPSystem.Common.Domains.Material;
using ERPSystem.Common.DTO;
using ERPSystem.Common.Infrastructure.IRepository;
using MediatR;

namespace BasicInformationCommon.API.BasicInformationCommons.Materiales
{
    public class MeasureunitsQueryHandler:IRequestHandler<MeasureunitsQueryCommand,Result>
    {
        private readonly IBaseRepository<Measureunit> measureunitRequest;

        public MeasureunitsQueryHandler(IBaseRepository<Measureunit> measureunitRequest)
        {
            this.measureunitRequest = measureunitRequest;
        }

        /// <summary>
        /// 计量单位下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Result> Handle(MeasureunitsQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            try
            {
                var measureunitsList = await (await measureunitRequest.GetAll()).ToListAsync();
                result.Data = measureunitsList;
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
